<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>门店工位配置</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span>
    基础配置
    <span class="c-gray en">&gt;</span>
    工位类型配置
</nav>
<div class="page-container">
    <div id="merchantBasicStationToolbar">
        <form class="form-inline" id="merchantBasicStationForm">
            <div class="form-group">
                <label class="control-label" title="">
                    工位类型名称：
                </label>
                <input type="text" class="form-control" placeholder="请输入工位类型名称" id="stationStore-positionTypeName" name="positionTypeName">
            </div>
            <div class="form-group">
                <label class="control-label" title="">
                    创建时间：
                </label>
                <input type="text" class="form-control input-text Wdate"  onfocus="WdatePicker({readOnly:true})" placeholder="请输入创建时间">
            </div>
            <span onclick="merchantBasicStationFun.searchAction();" class="btn btn-default">查询
                <i class="glyphicon glyphicon-search"></i>
            </span>&nbsp;&nbsp;&nbsp;&nbsp;
            <!--
            <a href="javascript:;" onclick="merchantBasicStationFun.delAll();" class="btn btn-danger radius">
                <i class="Hui-iconfont">&#xe6e2;</i> 批量删除
            </a>-->
            <a class="btn btn-primary radius" data-title="添加工位类型" data-href="merchant/basic/station_add.html"
               onclick="Hui_admin_tab(this)" href="javascript:;">
                <i class="Hui-iconfont">&#xe600;</i>
                添加工位类型
            </a>
        </form>

    </div>
    <div class="mt-20">
        <table id="basicStationTable" class="table table-border table-bordered table-bg table-hover table-sort">
        </table>
    </div>
</div>
<script type="text/javascript">
    /*服务类型配置 merchantStoreEquipmentFun*/
    var merchantBasicStationFun;

    merchantBasicStationFun = {
        init: function () {
            var _this = this;
            /****************ajax加载表格***********/
            $('#basicStationTable').bootstrapTable({
                url: 'biz/getAllWorkPositionByBizId',         //请求后台的URL（*）
                method: 'get',
                toolbar: '#merchantBasicStationToolbar',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,                   //是否显示分页（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,                   //是否显示父子表
                columns: [
                    {
                        checkbox: true
                    }, {
                        field: 'positionId',
                        title: '工位id',
                        visible: false
                    }, {
                        field: 'positionTypeName',
                        title: '工位类型名称'
                    }, {
                        field: 'positionDetail',
                        title: '工位类型'
                    }, {
                        field: 'addTime',
                        title: '创建时间'
                    },  {
                        field: 'address',
                        title: '操作',
                        formatter : function (value, row,index) {/***********同裂变营销的禁用启用删除************/
                            return `
                        <a class="btn btn-info btn-sm" href="javascript:;"data-title="修改工位"
                            data-href="merchant/basic/station_edit.html" onclick="Hui_admin_tab(this,'merchant-positionId','${row.positionId}')"> 修改
                        </a>
                        <!--<a class="btn btn-danger btn-sm" type="button"
                          onclick="merchantBasicStationFun.station_close('${row.packageId}','${row.packageState}')">禁用</a>
                        <a class="btn btn-success btn-sm" type="button"
                           onclick="merchantBasicStationFun.station_open('${row.packageId}','${row.packageState}')">启用</a>-->
                        <a class="btn btn-default btn-sm" onclick="merchantBasicStationFun.del_station('${row.positionId}')">删除</a>
                    `;
                        }
                    }
                ]
            });
            pageRefreshFun()//方法在index.html，点击表格刷新按钮，清空input搜索框
            /****ajax加载select2 门店名称********/
            $.ajax({
                type: "GET",
                url: "biz/getServiceTypeByBizId",/*改地址*/
                async: false,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        $("#stationStoreName").select2({
                            data: data.data,
                            placeholder: '请选择门店',
                            width: '195px'
                        });
                    }

                },
                error: function () {
                    alert("error2");
                }
            });
            /****ajax加载select2 工位类型********/
            $.ajax({
                type: "GET",
                url: "biz/getServiceTypeByBizId",/*改地址*/
                async: false,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        $("#stationType").select2({
                            data: data.data,
                            placeholder: '请选择工位类型',
                            width: '195px'
                        });
                    }

                },
                error: function () {
                    alert("error2");
                }
            });
        },
        refresh: function () {
            $('#basicStationTable').bootstrapTable("refresh");
        },
        //删除一个工位
        del_station : function (index) {
            layer.confirm('确认要删除吗？',
                {
                    btn: ['确定', '取消']
                },
                function () {
                    //确认删除
                    $.ajax({
                        type: "get",
                        url: 'biz/deleteWorkPosition?positionId='+index,
                        dataType: "json",
                        success: function (data) {
                            //state为true，删除成功
                            if (data.state) {
                                layer.msg(data.message, {icon: 1});

                                //刷新
                                $("#basicStationTable").bootstrapTable("refresh");

                                return true;
                            } else {
                                layer.msg(data.message, {icon: 2});
                                return false;
                            }
                        },
                        error: function () {
                            layer.msg('错误！', {icon: 2});
                            return false;
                        }
                    });

                },
                function () {
                    layer.msg('已取消！', {icon: 1});
                    return false;
                }
            );

        },
        //禁用一个工位
        station_close : function (index,state) {
            let _this = this;
            //判断该用户是否已经处于禁用
            if(state==0){
                layer.msg("该用户已经处于禁用状态！", {icon: 0});
                return;
            }

            $.ajax({
                type: "get",
                url: " "+index,
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table
                       // _this.reloadBootstrapTable("/mkt/showAllRegisterPackages","RegisterPackage");

                        return true;
                    }else {
                        layer.msg("禁用失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert('ajax地址错误');
                   // alert("error");
                }
            });
        },
        //启用一个工位
        station_open : function (index,state) {
            let _this = this;
            //判断该用户是否已经处于启用
            if(state==1){
                layer.msg("该用户已经处于启用状态！", {icon: 0});
                return;
            }

            $.ajax({
                type: "get",
                url: " "+index,
                dataType: "json",
                success : function(data) {
                    if(data.state){
                        layer.msg(data.message, {icon: 1});
                        //涮新table
                       // _this.reloadBootstrapTable("/mkt/showAllRegisterPackages","RegisterPackage");

                        return true;
                    }else {
                        layer.msg("启用失败！", {icon: 2});
                        return false;
                    }

                },
                error:function () {
                    alert('ajax地址错误');
                    //alert("error");
                }
            });
        },
        //批量删除
        delAll: function () {
            let _this = this;
            layer.confirm('确认要删除吗？',
                {
                    btn: ['确定','取消']
                },
                function(){
                    //确认删除
                    //获取所有被选中的记录
                    var rows = $("#basicStationTable").bootstrapTable('getSelections');
                    if (rows.length== 0) {
                        layer.alert("请先选择要删除的记录!");
                        return;
                    }
                    var ids = '';
                    for (var i = 0; i < rows.length; i++) {
                        ids += rows[i]['serviceId'] + ",";
                    }
                    ids = ids.substring(0, ids.length - 1);
                    //删除
                    $.ajax({
                        type: "get",
                        url: "biz/deleteAllByBizId",
                        data:{list:ids},
                        dataType: "json",
                        success : function(data) {
                            if(data.state){
                                layer.msg(data.message, {icon: 1});
                                //涮新一次
                                $('#basicStationTable').bootstrapTable("refresh");

                                return true;
                            }else {
                                layer.msg("批量删除失败！", {icon: 2});
                                return false;
                            }

                        },
                        error:function () {
                            alert('ajax地址错误');
                          //  alert("error");
                        }
                    });

                },
                function(){
                    layer.msg('已取消！', {icon: 1});
                    return false;
                }
            );
        },
        searchAction : function () {
            $.ajax({
                type: "get",
                url: "biz/getAllWorkPositionByBizId",
                data:$("#merchantBasicStationForm").serializeArray(),
                dataType: "json",
                success : function(json) {
                    if(json.state){
                        $("#basicStationTable").bootstrapTable('load', json.data);
                    }else {
                        alert("error");
                    }
                },
                error:function () {
                    alert("error");
                }
            });
        }
    };

    merchantBasicStationFun.init();
</script>
</body>
</html>